vimfandomcom-20200223-history
Integrate gvim with Visual Studio
On Windows systems, you may be able to integrate Vim with Microsoft Visual Studio. Integration of Vim with Visual Studio 2003 and later Script includes features: *Compatible with Visual Studio 2003, 2005, 2008, and 2010 *Control Visual Studio from within Vim. *Load the current Visual Studio file into Vim. *Load the current Vim file into Visual Studio. *Compile the current file (C/C++) within Vim. *Build the current project (C/C++/C#) within Vim. *Load results from Visual Studio into the Vim quickfix file. ViEmu for Visual Studio is commercial software that emulates Vim editing commands within Visual Studio (Vim is not used). Vim as an External Tool If you like Vim and use MS Visual Studio .NET for debugging and want a lightweight way to open the file you're currently debugging in VS in Vim, you can add Vim as an external tool. This will let you use a single keystroke to open the current VS file in vim with the cursor at the same line and even at the same column. The Tool: In Visual Studio, Tools > External Tools > Add: *''Title:'' &Vim *''Command:'' C:\Vim\vim73\gvim.exe *''Arguments:'' --servername VimualStudio --remote-silent +"call cursor($(CurLine),$(CurCol))" $(ItemFileName)$(ItemExt) *''Initial directory:'' $(ItemDir) If you have other settings you'd like to apply (like normal zz to centre the cursor or updating path for :find, then you can put them in ~/.vim/visualstudioinvoke.vim and add +"runtime visualstudioinvoke.vim" before $(ItemFileName). The Shortcut: In Visual Studio, Tools -> Options -> Keyboard: *''Command:'' ExternalCommand1 (it's easiest if you move your Vim external tool to be the first, otherwise use the correct index). *''Shortcut key:'' This will allow you to use your key combination to open the current file at the current line and cursor in a new vim browser. The browser will start at the directory of that file, so ':e .' will edit the directory of that file. Remove the --servername VimualStudio part if you want it to open a new instance of Vim each time. Preventing Nagging: In order to effectively use the two together and make sure .NET does not complain about its files changing, goto Tools > Options > Environment > Documents and ensure these two options are checked: *Detect when file is changed outside the environment. *Auto-load changes (if not currently modified inside the environment). You should set up ctags and Omni_completion. Opening Vim file in Visual Studio Much like vim's --remote, you can run devenv with the edit parameter to open a file in an existing visual studio. This command abbreviation opens the file you're currently editing, but doesn't transfer line or column postition. :cabbrev vsedit :!"c:\Program Files\Microsoft Visual Studio 8\Common7\ide\devenv.exe" /edit "%" VisVim for Visual Studio 5.0 and 6.0 *The OLE version of gvim can be used as the editor in Visual Studio 5.0 and 6.0. This is called VisVim . *The source code for Vim includes directory src/VisVim which allows building file VisVim.dll. *File src/VisVim/README_VisVim.txt is the documentation. *With VisVim, you can use Visual Studio for designing and building, and use Vim commands within Visual Studio for editing. *VisVim does not work with Visual Studio 2002 and later (Visual Studio .NET). However the Visual Studio versions after VS6 support use of an external editor. See also Todo Merge some of following: *345 Quickfix and Visual Studio and cygwin keep this separate as the "with cygwin" tip *368 Use gvim in VS.Net *580 Switching between Vim and Visual Studio ability to move back and forth between Vim and VS *683 Integrate gvim with Visual Studio (see "Original tip" below) *716 Calling gvim from MS Visual Studio *719 Use Python to build project in Visual Studio *946 VisVim for Visual Studio Comments